package cn.easybuy.service;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class GouWuChe extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		String id1 = request.getParameter("id");
		int id = Integer.parseInt(id1);
		String[] names = { "化妆品", "家用商品", "电子商品", "箱包", "进口食品,生鲜", "保健食品" };
		String name = names[id - 1];
		Map<String, Integer> map = (Map<String, Integer>) request.getSession()
				.getAttribute("cart");
		if (name == null) {
			map = new HashMap<String, Integer>();
			map.put(name, 1);

		} else {
			if (map.containsKey(name)) {
				int num = map.get(name);
				map.put(name, num + 1);

			} else {
				map.put(name, 1);
			}
		}
		request.getSession().setAttribute("cart1", map);
		response.getWriter().write(
				"<a href='#'>继续购物</a>" + " <a href='#'>结算</a>");
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doGet(request, response);
	}

}
